/**
 * @author sanyu0302
 * @qq  757178971
 * @description:
 */

package com.wehealth.widget;
import com.wehealth.R;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.PathEffect;
import android.util.AttributeSet;
import android.view.View;
public class PressureGridChart extends GridChart{
    
    private static final String TAG="PressureGridChart";

 
    
    private String[] resultValue;
    private int valuesum = 20;


    public PressureGridChart(Context context) {
        this(context, null);
        // TODO Auto-generated constructor stub
    }
    
    public PressureGridChart(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
        // TODO Auto-generated constructor stub
    }
    
    public PressureGridChart(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        // TODO Auto-generated constructor stub
    }
    

    
    
    @Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        super.onDraw(canvas);
        setBackgroundResource(R.drawable.bg_white_cirecle);
        /** 获取整个View的宽高 */
        int viewHeight = getHeight();
        int viewWidth = getWidth();
        drawResultLineBlue(canvas);
    }

    public void setResultValuesBlue(String[] vaules,int sum){
        resultValue = vaules;
        valuesum = sum;
        invalidate();
      }
    
    private void drawResultLineBlue(Canvas canvas){
        if(resultValue!=null && resultValue.length>0){
            Paint paint = new Paint();
            paint.setStyle(Style.STROKE);
            paint.setStrokeWidth(2);
            paint.setColor(getResources().getColor(R.color.color_blue_health_chart));
            
            Paint paintCircle = new Paint();
            paintCircle.setStyle(Style.FILL);
            paintCircle.setColor(getResources().getColor(R.color.color_blue_health_chart));
            
            float[] x = new float[7];
            float[] y = new float[7];
            
            for(int i = 0; i < 7;i++){
                x[i] = default_left_text_space_width+default_left_right_margin_width + 
                        longitudeSpacing * i;
               }
            
            for(int j =0 ; j<7;j++){   
                float realvalues = Float.valueOf(resultValue[j]);  
                float times = valuesum/20;     
                float values =realvalues/times;
                y[j] = default_margin_top+1+latitudeSpacing*(20-(int)values)+
                		latitudeSpacing*(values - (int)values);
             }

          for(int n=0;n<6;n++){  
            canvas.drawLine(x[n], y[n],x[n+1], y[n+1], paint);
            canvas.drawCircle(x[n], y[n], 8, paintCircle);
            }
          canvas.drawCircle(x[6], y[6], 8, paintCircle);
        }
    }
    

}
